package cc.telecomdigital.tdstock.trading.Common;

import cc.telecomdigital.tdstock.trading.Tools.Trade_StockFunctionTools;

public class Trade_StockHoldItem
{
	public  String	 stockCode;
	public  String	 chnName;
	public  String	 engName;
	public  String	 onHandVolume;
	public  String	 lastClosedPrice;
	public  String	 totalWorth;
	public  String	 currencyType;
	public  String	 rate;	
	private boolean isShortSale;

	/** Item for storage for GetPorfolio **/
	public Trade_StockHoldItem(String iCode, String iChnName, String iEngName,
			String iOnHandVol, String iLastPrice, String iWorth, String iCurrencyType, String iRate)
	{
		stockCode = iCode;
		chnName = iChnName;
		engName = iEngName;
		lastClosedPrice = iLastPrice;
		totalWorth = iWorth;
		isShortSale = false;
		currencyType = iCurrencyType;
		rate         = iRate;
		onHandVolume = iOnHandVol;
		// Check the correct volume for the stock record
		if ((iOnHandVol != null) && (iOnHandVol.length() > 0))
		{
			if (iOnHandVol.substring(0, 1).equals("-"))
			{
				isShortSale = true;
				try
				{
					iOnHandVol = iOnHandVol.substring(1,iOnHandVol.length());
					onHandVolume = iOnHandVol;
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
				}
			}
		}
	}

	public boolean IsShortSale()
	{
		return isShortSale;
	}
	
	public Trade_StockHoldItem(String iCode, String iChnName, String iEngName,
			String iOnHandVol, String iLastPrice, String iCurrencyType, String iRate)
	{
		stockCode = iCode;
		chnName = iChnName;
		engName = iEngName;
		lastClosedPrice = iLastPrice;
		isShortSale = false;
		totalWorth = "0.00";
		onHandVolume = iOnHandVol;
		currencyType = iCurrencyType;
		rate         = iRate;
		// Check the correct volume for the stock record
		if ((iOnHandVol != null) && (iOnHandVol.length() > 0))
		{
			if (iOnHandVol.substring(0, 1).equals("-"))
			{
				isShortSale = true;
				try
				{
					iOnHandVol = iOnHandVol.substring(1,
							iOnHandVol.length());
					onHandVolume = iOnHandVol;
					totalWorth = Trade_StockFunctionTools
							.CalculateProductInPrice(iLastPrice, onHandVolume);
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
				}
			}
			else
			{
				totalWorth = Trade_StockFunctionTools
						.CalculateProductInPrice(iLastPrice, onHandVolume);
			}
		}
	}

	public Trade_StockHoldItem(Trade_StockHoldItem iItem)
	{
		stockCode = iItem.stockCode;
		chnName = iItem.chnName;
		engName = iItem.engName;
		lastClosedPrice = iItem.lastClosedPrice;
		totalWorth = iItem.totalWorth;
		isShortSale = iItem.isShortSale;
		onHandVolume = iItem.onHandVolume;
		currencyType = iItem.currencyType;
		rate = iItem.rate;
	}

}
